package oschina.zhangchaozheng.demo.demo_1_7;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import oschina.zhangchaozheng.demo.demo_1_7.mapper.UserMapper;
import oschina.zhangchaozheng.demo.demo_1_7.model.User;

import javax.annotation.PostConstruct;
import java.util.Arrays;

/**
 * Created by zcz on 2017/6/28.
 */
@SpringBootApplication
public class Application {

    private Logger logger = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    private UserMapper userMapper;

    @PostConstruct
    public void test() {
        User user = new User();
        user.setName("Hello World!");
        user.setAge(10);
        int result = userMapper.createUser(user);
        logger.info("Create user result = {}", result);
    }
    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
        return args -> {
            logger.info("Let's inspect the beans provided by Spring Boot:");
            String[] beanNames = ctx.getBeanDefinitionNames();
            Arrays.sort(beanNames);
            for (String beanName : beanNames) {
                logger.info(beanName);
            }
        };
    }
}
